<%@ page contentType="text/html;charset=ISO8859_1" language="java" %>

<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-nested.tld" prefix="nested" %>

<jsp:useBean id="oLogon" class="git.bankview.wl.bean.LogonBean" scope="session" />
<jsp:useBean id="context" type="laya.semi.process.IProcessContext" scope="request" />
<jsp:useBean id="oNavigate" class="git.bankview.wl.bean.TransNavigateBean" />
<jsp:setProperty name="oNavigate" property="transid" />
<% boolean bHasInputMethod = "1".equals((String)context.getField("hasInputMethod")); %>

<html:html locale="true">
<head>
	<title><logic:iterate id="element" name="oNavigate" property="navigateList"
	><bean:write name="element" property="translabel" />
	 - </logic:iterate><bean:message key="report.NewReportTrans.title" /></title>
	<!-- title><bean:message key="report.NewReportTrans.title" /></title -->
	<link rel="stylesheet" href="../style/default_aux.css">
	<link rel="stylesheet" href="../style/pp.css">
</head>
<body onload="oninit();">
	<script src="../script/overlib.js" language="JavaScript"></script>
	<script src="../script/style.js" language="JavaScript"></script>
	<script src="../script/windows.js" language="JavaScript"></script>
	<table cellspacing="0" class="filledframe">
		<tr>
			<td nowrap="" class="clientframe">
				<table id="oHelp" class="helper" >
					<tr>
						<td width="200" class="label">&nbsp;</td>
						<td class="help"><input type="button" class="button" title="<bean:message key="common.help.title" />" onclick="help('help.report.schd');" value="<bean:message key="common.help" />" ></td>
					</tr>
				</table>
				<html:form action="/report/SetTransAuth" styleId="oSetForm" onsubmit="return onSubmitCheck()">
					<html:hidden property="transid" />
					<html:hidden property="translabel" />
					<input type="hidden" name="methodid" value="<%=request.getAttribute("methodid")%>" />
					<input type="hidden" name="pageUrl" value="<html:rewrite action="/report/ReportSchdList" />?transid=<bean:write name="RoleTransForm" property="transid" />" />
					<div class="listtitle"><logic:iterate id="element" name="oNavigate" property="navigateList"
						><logic:empty name="element" property="pageurl"><bean:write name="element" property="translabel" /></logic:empty
						><logic:notEmpty name="element" property="pageurl"><a href="<bean:write name="element" property="pageurl" />" title="<bean:write name="element" property="transid" />"><bean:write name="element" property="translabel" /></a></logic:notEmpty
						><img src="/images/navconn.gif" ></logic:iterate><bean:message key="report.setTransAuth.title" 
						/></div>
					<!-- div class="listtitle"><bean:message key="report.setTransAuth.title" /> - <bean:write name="RoleTransForm" property="translabel" /></div -->
					<div class="subtitle"><bean:message key="report.setTransAuth.subtitle" />
						<br><html:errors /></div>
					<table id="oPropPagesTab"></table>
					
					<!---------------- role auth page BEGIN ----------------->
					<div id="ppRoles">
						<table width="100%" height="100%" cellspacing="0" class="formpanel">
							<tr><td class="line"><img src="/images/spacer.gif"></td></tr>
							<tr><td class="line"><bean:message key="report.role.namelist" />:</td></tr>
							<tr><td class="input">
								<div id="oRoleList"></div>
							</td></tr>
							<tr><td class="line" align="right">
								<input type="button" tabindex="410" class="button" 
									value="<bean:message key="common.add" />..." onclick="openNavigator('<html:rewrite action="/auth/RoleSelector" />', 'addRole', 560, 398)">
								<input type="button" tabindex="415" class="button" 
									value="<bean:message key="common.delete" />" onclick="deleteSelectedRow(oRoleList)">
							</td></tr>
							<tr><td class="line"><hr></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="report.role.authlist" />:</td>
								<td nowrap width="32"><bean:message key="auth.allowed" /></td>
								<td nowrap style="padding-left: 25px; "><bean:message key="auth.desc" /></td></tr></table></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.view" /></td>
								<td nowrap width="32"><input type="checkbox" name="roleView" tabindex="420" onclick="maskLink(this, oSetForm.roleUse, false); saveRoleRights(); " value="0" ></td>
								<td nowrap ><bean:message key="auth.view.desc" /></td>
							</tr></table></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.use" /></td>
								<td nowrap width="32"><input type="checkbox" name="roleUse" tabindex="420" onclick="maskLink(this, oSetForm.roleView, true); maskLink(this, oSetForm.<%=bHasInputMethod ? "roleInput" : "roleModify"%>, false); saveRoleRights(); " value="0" ></td>
								<td nowrap ><bean:message key="auth.use.desc" /></td>
							</tr></table></td></tr>
							<% if (bHasInputMethod) { %><tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.input" /></td>
								<td nowrap width="32"><input type="checkbox" name="roleInput" tabindex="420" onclick="maskLink(this, oSetForm.roleUse, true); maskLink(this, oSetForm.roleModify, false); saveRoleRights(); " value="0" ></td>
								<td nowrap ><bean:message key="auth.input.desc" /></td>
							</tr></table></td></tr><% } %>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.modify" /></td>
								<td nowrap width="32"><input type="checkbox" name="roleModify" tabindex="420" onclick="maskLink(this, oSetForm.<%=bHasInputMethod ? "roleInput" : "roleUse"%>, true); maskLink(this, oSetForm.roleOwner, false); saveRoleRights(); " value="0" ></td>
								<td nowrap ><bean:message key="auth.modify.desc" /></td>
							</tr></table></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.owner" /></td>
								<td nowrap width="32"><input type="checkbox" name="roleOwner" tabindex="420" onclick="maskLink(this, oSetForm.roleModify, true); saveRoleRights(); " value="0" ></td>
								<td nowrap ><bean:message key="auth.owner.desc" /></td>
							</tr></table></td></tr>
							<tr><td class="line"><img src="/images/spacer.gif"></td></tr>
						</table>
					</div>
					<!---------------- role auth page END ----------------->
					
					<!---------------- user auth page BEGIN ----------------->
					<div id="ppUsers">
						<table width="100%" height="100%" cellspacing="0" class="formpanel">
							<tr><td class="line">&nbsp;</td></tr>
							<tr><td class="line"><bean:message key="report.user.namelist" />:</td></tr>
							<tr><td class="input">
								<div id="oUserList"></div>
							</td></tr>
							<tr><td class="line" align="right">
								<input type="button" tabindex="410" class="button" 
									value="<bean:message key="common.add" />..." onclick="openNavigator('<html:rewrite action="/auth/UserSelector" />', 'addUser', 560, 398)">
								<input type="button" tabindex="415" class="button" 
									value="<bean:message key="common.delete" />" onclick="deleteSelectedRow(oUserList)">
							</td></tr>
							<tr><td class="line"><hr></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="report.user.authlist" />:</td>
								<td nowrap width="32"><bean:message key="auth.allowed" /></td>
								<td nowrap width="32"><bean:message key="auth.denied" /></td>
								<td nowrap style="padding-left: 25px; "><bean:message key="auth.desc" /></tr></table></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.view" /></td>
								<td nowrap width="32"><input type="checkbox" name="userView" tabindex="420" onclick="if (this.checked) oSetForm.userView[1].checked = false; maskLink(this, oSetForm.userUse[0], false); saveUserRights(); " value="0" ></td>
								<td nowrap width="32"><input type="checkbox" name="userView" tabindex="420" onclick="if (this.checked) oSetForm.userView[0].checked = false; maskLink(this, oSetForm.userUse[1], true); saveUserRights(); " value="1" ></td>
								<td nowrap ><bean:message key="auth.view.desc" /></td>
							</tr></table></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.use" /></td>
								<td nowrap width="32"><input type="checkbox" name="userUse" tabindex="420" onclick="if (this.checked) oSetForm.userUse[1].checked = false; maskLink(this, oSetForm.userView[0], true); maskLink(this, oSetForm.<%=bHasInputMethod ? "userInput" : "userModify"%>[0], false); saveUserRights(); " value="0" ></td>
								<td nowrap width="32"><input type="checkbox" name="userUse" tabindex="420" onclick="if (this.checked) oSetForm.userUse[0].checked = false; maskLink(this, oSetForm.<%=bHasInputMethod ? "userInput" : "userModify"%>[1], true); maskLink(this, oSetForm.userView[1], false); saveUserRights(); " value="1" ></td>
								<td nowrap ><bean:message key="auth.use.desc" /></td>
							</tr></table></td></tr>
							<% if (bHasInputMethod) { %><tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.input" /></td>
								<td nowrap width="32"><input type="checkbox" name="userInput" tabindex="420" onclick="if (this.checked) oSetForm.userInput[1].checked = false; maskLink(this, oSetForm.userUse[0], true); maskLink(this, oSetForm.userModify[0], false); saveUserRights(); " value="0" ></td>
								<td nowrap width="32"><input type="checkbox" name="userInput" tabindex="420" onclick="if (this.checked) oSetForm.userInput[0].checked = false; maskLink(this, oSetForm.userModify[1], true); maskLink(this, oSetForm.userUse[1], false); saveUserRights(); " value="1" ></td>
								<td nowrap ><bean:message key="auth.input.desc" /></td>
							</tr></table></td></tr><% } %>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.modify" /></td>
								<td nowrap width="32"><input type="checkbox" name="userModify" tabindex="420" onclick="if (this.checked) oSetForm.userModify[1].checked = false; maskLink(this, oSetForm.<%=bHasInputMethod ? "userInput" : "userUse"%>[0], true); maskLink(this, oSetForm.userOwner[0], false); saveUserRights(); " value="0" ></td>
								<td nowrap width="32"><input type="checkbox" name="userModify" tabindex="420" onclick="if (this.checked) oSetForm.userModify[0].checked = false; maskLink(this, oSetForm.userOwner[1], true); maskLink(this, oSetForm.<%=bHasInputMethod ? "userInput" : "userUse"%>[1], false); saveUserRights(); " value="1" ></td>
								<td nowrap ><bean:message key="auth.modify.desc" /></td>
							</tr></table></td></tr>
							<tr><td class="line"><table cellspacing="0"><tr>
								<td nowrap class="label"><bean:message key="auth.owner" /></td>
								<td nowrap width="32"><input type="checkbox" name="userOwner" tabindex="420" onclick="if (this.checked) oSetForm.userOwner[1].checked = false; maskLink(this, oSetForm.userModify[0], true); saveUserRights(); " value="0" ></td>
								<td nowrap width="32"><input type="checkbox" name="userOwner" tabindex="420" onclick="if (this.checked) oSetForm.userOwner[0].checked = false; maskLink(this, oSetForm.userModify[1], false); saveUserRights(); " value="1" ></td>
								<td nowrap ><bean:message key="auth.owner.desc" /></td>
							</tr></table></td></tr>
							<tr><td class="line">&nbsp;</td></tr>
						</table>
					</div>
					<!---------------- user auth page END ----------------->
					
					<table width="500" class="formpanelbar">
						<tr>
							<td align="right" nowrap="">
								<html:submit tabindex="1001" styleClass="button"><bean:message key="common.submit" /></html:submit></td>
						</tr>
					</table>
				</html:form>
			</td>
			<!-- td id="oFrame" nowrap="" class="infoframe">&nbsp;</td -->
		</tr>
	</table>
	
	<iframe id="oDataGetter" style="display: none; "></iframe>
	
<script language="javascript">
function oninit()
{
	initPropertyPageTable(oPropPagesTab, 500, 320);
	addPropertyPage(oPropPagesTab, ppRoles, "<bean:message key="report.pp.roles" />");
	addPropertyPage(oPropPagesTab, ppUsers, "<bean:message key="report.pp.users" />");
	setPropertyPageActive(oPropPagesTab, 0);
	
	initSelectControl(oRoleList, "100%", 80, new Array("30%", "70%"), onRoleItemSelect);
	
	var roleids = new Array(0);
	var rolelabels = new Array(0);
	var rolemethodids = new Array(0);
	var rolestatuscodes = new Array(0);

	var userids = new Array(0);
	var usernames = new Array(0);
	var usermethodids = new Array(0);
	var userstatuscodes = new Array(0);
	
	var i;

	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="roleids">
		roleids[i++] = "<bean:write name="element" />"; </logic:iterate>
	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="rolelabels">
		rolelabels[i++] = "<bean:write name="element" />"</logic:iterate>
	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="rolemethodids">
		rolemethodids[i++] = <bean:write name="element" /></logic:iterate>
	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="rolestatuscodes">
		rolestatuscodes[i++] = <bean:write name="element" /></logic:iterate>

	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="userids">
		userids[i++] = "<bean:write name="element" />"</logic:iterate>
	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="usernames">
		usernames[i++] = "<bean:write name="element" />"</logic:iterate>
	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="usermethodids">
		usermethodids[i++] = <bean:write name="element" /></logic:iterate>
	i = 0;
	<logic:iterate id="element" name="RoleTransForm" property="userstatuscodes">
		userstatuscodes[i++] = <bean:write name="element" /></logic:iterate>

	var rowOfRole = null;
	for (i = 0; i < roleids.length; ++i)
	{
		if (null == rowOfRole || rowOfRole.cells[0].innerText != roleids[i])
			rowOfRole = buildAuthRow(oRoleList, new Array(roleids[i], rolelabels[i]));
		
		setMethodSc(rowOfRole, rolemethodids[i], rolestatuscodes[i]);
	}
	
	var currRoleRow = getSelectedRow(oRoleList);
	if (null != currRoleRow)
		loadRoleRights(currRoleRow);
	
	initSelectControl(oUserList, "100%", 80, new Array("30%", "70%"), onUserItemSelect);
	var rowOfUser = null;
	for (i = 0; i < userids.length; ++i)
	{
		if (null == rowOfUser || rowOfUser.cells[0].innerText != userids[i])
			rowOfUser = buildAuthRow(oUserList, new Array(userids[i], usernames[i]));
		
		setMethodSc(rowOfUser, usermethodids[i], userstatuscodes[i]);
	}
	var currUserRow = getSelectedRow(oUserList);
	if (null != currUserRow)
		loadUserRights(currUserRow);
}
function buildAuthRow(ctrl, vTxt)
{
	row = insertRow(ctrl, vTxt);
	row.authView = -1;
	row.authUse = -1;
	<% if (bHasInputMethod) { %>row.authInput = -1;<% } %>
	row.authModify = -1;
	row.authOwner = -1;
	return row;
}
function setMethodSc(row, m, sc)
{
	switch(m)
	{
		case 0x01: row.authView = sc; break;
		case 0x03: row.authUse = sc; break;
		<% if (bHasInputMethod) { %> case 0x05: row.authInput = sc; break; <% } %>
		case 0x0d: row.authModify = sc; break;
		case 0xff: row.authOwner = sc; break;
		default: alert("error method: '" + m + "'");
	}
}
function onRoleItemSelect(row)
{
	loadRoleRights(row);
	return true;
}
function onUserItemSelect(row)
{
	loadUserRights(row);
	return true;
}
function onSubmitCheck()
{
	clearParameters(oSetForm, "roleids");
	clearParameters(oSetForm, "rolelabels");
	clearParameters(oSetForm, "rolemethodids");
	clearParameters(oSetForm, "rolestatuscodes");
	clearParameters(oSetForm, "userids");
	clearParameters(oSetForm, "usernames");
	clearParameters(oSetForm, "usermethodids");
	clearParameters(oSetForm, "userstatuscodes");
	
	appendRoleRecords();
	appendUserRecords();
	
	return true;
}
function appendRoleRecords()
{
	var rows = getAllRows(oRoleList);
	var i;
	for (i = 0; i < rows.length; ++i)
	{
		appendRoleParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authView, 0x01);
		appendRoleParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authUse, 0x03);
		<% if (bHasInputMethod) { %>appendRoleParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authInput, 0x05);<% } %>
		appendRoleParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authModify, 0x0d);
		appendRoleParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authOwner, 0xff);
	}
}
function appendRoleParameters(f, rid, rlabel, sc, m)
{
	if (-1 < sc)
	{
		// alert(rid + ":" + ulabel + ":" + sc + ":" + m);
		appendParameter(f, "roleids", rid);
		appendParameter(f, "rolelabels", rlabel);
		appendParameter(f, "rolemethodids", m);
		appendParameter(f, "rolestatuscodes", sc);
	}
}
function appendUserRecords()
{
	var rows = getAllRows(oUserList);
	var i;
	for (i = 0; i < rows.length; ++i)
	{
		appendUserParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authView, 0x01);
		appendUserParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authUse, 0x03);
		<% if (bHasInputMethod) { %>appendUserParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authInput, 0x05);<% } %>
		appendUserParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authModify, 0x0d);
		appendUserParameters(oSetForm, rows[i].cells[0].innerText, rows[i].cells[1].innerText
			, rows[i].authOwner, 0xff);
	}
}
function appendUserParameters(f, uid, ulabel, sc, m)
{
	if (-1 < sc)
	{
		// alert(uid + ":" + ulabel + ":" + sc + ":" + m);
		appendParameter(f, "userids", uid);
		appendParameter(f, "userlabels", ulabel);
		appendParameter(f, "usermethodids", m);
		appendParameter(f, "userstatuscodes", sc);
	}
}
function loadUserRights(uRow)
{
	loadUserRightMethod(oSetForm.userView, uRow.authView);
	loadUserRightMethod(oSetForm.userUse, uRow.authUse);
	<% if (bHasInputMethod) { %>loadUserRightMethod(oSetForm.userInput, uRow.authInput);<% } %>
	loadUserRightMethod(oSetForm.userModify, uRow.authModify);
	loadUserRightMethod(oSetForm.userOwner, uRow.authOwner);
}
function loadUserRightMethod(c, statusCode)
{
	c[0].checked = (0 == statusCode);
	c[1].checked = (1 == statusCode);
}
function saveUserRights()
{
	var uRow = getSelectedRow(oUserList);
	if (null != uRow)
	{
		uRow.authView = getUserRightMethod(oSetForm.userView);
		uRow.authUse = getUserRightMethod(oSetForm.userUse);
		<% if (bHasInputMethod) { %>uRow.authInput = getUserRightMethod(oSetForm.userInput);<% } %>
		uRow.authModify = getUserRightMethod(oSetForm.userModify);
		uRow.authOwner = getUserRightMethod(oSetForm.userOwner);
	}
}
function getUserRightMethod(c)
{
	if (c[0].checked)
		return 0;
	else if (c[1].checked)
		return 1;
	
	return -1; // undefined
}
function loadRoleRights(uRow)
{
	loadRoleRightMethod(oSetForm.roleView, uRow.authView);
	loadRoleRightMethod(oSetForm.roleUse, uRow.authUse);
	<% if (bHasInputMethod) { %>loadRoleRightMethod(oSetForm.roleInput, uRow.authInput);<% } %>
	loadRoleRightMethod(oSetForm.roleModify, uRow.authModify);
	loadRoleRightMethod(oSetForm.roleOwner, uRow.authOwner);
}
function loadRoleRightMethod(c, statusCode)
{
	c.checked = (0 == statusCode);
}
function saveRoleRights()
{
	var rRow = getSelectedRow(oRoleList);
	if (null != rRow)
	{
		rRow.authView = getRoleRightMethod(oSetForm.roleView);
		rRow.authUse = getRoleRightMethod(oSetForm.roleUse);
		<% if (bHasInputMethod) { %>rRow.authInput = getRoleRightMethod(oSetForm.roleInput);<% } %>
		rRow.authModify = getRoleRightMethod(oSetForm.roleModify);
		rRow.authOwner = getRoleRightMethod(oSetForm.roleOwner);
	}
}
function getRoleRightMethod(c)
{
	return c.checked ? 0 : -1;
}
function addRole(vField)
{
	if (-1 == indexOfRow(oRoleList, 0, vField[0]))
	{
		var row = buildAuthRow(oRoleList, vField);
		row.authView = 0;
		var currRoleRow = getSelectedRow(oRoleList);
		if (null != currRoleRow)
			loadRoleRights(currRoleRow);
	}
}
function addUser(vField)
{
	if (-1 == indexOfRow(oUserList, 0, vField[0]))
	{
		var row = buildAuthRow(oUserList, vField);
		row.authView = 0;
		var currUserRow = getSelectedRow(oUserList);
		if (null != currUserRow)
			loadUserRights(currUserRow);
	}
}
</script>

</body>
</html:html>

